package cn.itsource.controller.app;

import cn.itsource.pojo.app.bo.CustomerDetailBo;
import cn.itsource.pojo.app.bo.FlushCustomerBo;
import cn.itsource.pojo.app.vo.AdvanceVo;
import cn.itsource.pojo.app.vo.CreateOrderVo;
import cn.itsource.result.R;
import cn.itsource.service.IOrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 📖：beishan
 * 🗓️：2024/4/10 19:30
 * =====================
 */
@RestController
@RequestMapping("/app/customer")
public class CustomerController {
    @Autowired
    private IOrderService orderService;

    @Operation( summary= "订单详情",description = "订单详情")
    @GetMapping("/detail/{orderNo}")
    public R detail(@PathVariable String orderNo){
        CustomerDetailBo detail = orderService.detail(orderNo);
        return R.success(detail);
    }

    @Operation( summary= "根据状态回显订单信息",description = "根据状态回显订单信息")
    @GetMapping("/flush")
    public R flush(){
        FlushCustomerBo flushCustomerBo  = orderService.flush();
        return R.success(flushCustomerBo);
    }

    @Operation( summary= "拉取订单状态",description = "拉取订单状态")
    @GetMapping("/pull/{orderNo}")
    public R pullOrderStatus(@PathVariable String orderNo){
        Boolean b = orderService.pullOrderStatus(orderNo);
        return R.success(b);
    }

    @Operation( summary= "取消订单",description = "取消订单")
    @PostMapping("/change/{id}")
    public R change(@PathVariable("id") String id){
        orderService.change(id);
        return R.success();
    }

    @Operation( summary= "自动取消订单",description = "自动取消订单")
    @PostMapping("/autochange/{id}")
    public R autochange(@PathVariable("id") String id){
        orderService.autochange(id);
        return R.success();
    }


    @Operation( summary= "预付订单创建",description = "预付订单创建")
    @Parameter(name = "advance",description = "预付订单创建",required = true)
    @PostMapping("/order/advance")
    public R advance(@RequestBody @Valid AdvanceVo vo){
        List<CreateOrderVo> createOrderVoList = orderService.advance(vo);
        return R.success(createOrderVoList);
    }

}
